import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import { AtTabBar } from 'taro-ui'
import requets from '../service/api'
import './index.scss'
Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,                 //月份 
        "d+": this.getDate(),                    //日 
        "h+": this.getHours(),                   //小时 
        "m+": this.getMinutes(),                 //分 
        "s+": this.getSeconds(),                 //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds()             //毫秒 
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}
export default class AtTabBar_index extends Component {

    state = {
        userId:'',
        count:0
    }

    componentWillMount() { }

    componentDidMount() {

    }
    pagingQueryCollectorRecord = (page, rows) => {

        let params = {
            collectorDate: new Date().format("yyyy-MM-dd"),
            hospitalId: '',
            level: '',
            page: 1,
            rows: 10,
            status: 0,
            userId: this.state.userId
        }
        requets.baseOptions({
            url: `/zjn-web/zjn/collector/dispatch/pagingQuery`,
            method: 'POST',
            data: params
        }).then((res) => {
            console.log(res)
            if (res.data.rc === 0) {
                    this.setState({
                        count: res.data.ret.count
                    })
            }
        })


    }

    componentWillUnmount() { }

    componentDidShow() { }

    componentDidHide() { }

    handleClick = (v) => {
        console.log(v)
        this.pagingQueryCollectorRecord()
        if (v == 0) {
            // 跳转到目的页面，打开新页面
            Taro.redirectTo({
                url: '/pages/index_GL/index'
            })

        }

        if (v == 1) {
            // 跳转到目的页面，打开新页面
            Taro.redirectTo({
                url: '/pages/renwu_GL/index'
            })

        }

        if (v == 2) {
            // 跳转到目的页面，打开新页面
            Taro.redirectTo({
                url: '/pages/history_GL/index'
            })

        }

        if (v == 3) {
            // 跳转到目的页面，打开新页面
            Taro.redirectTo({
                url: '/pages/me_GL/index'
            })

        }
    }


    render() {
        const {count} = this.state
        return (
            <AtTabBar
                fixed
                tabList={[
                    { title: '需求上报', iconType: 'shopping-bag'},
                    { title: '消息', iconType: 'menu'},
                    { title: '收集历史', iconType: 'filter' },
                    { title: '我的', iconType: 'home' }
                ]}
                onClick={this.handleClick.bind(this)}
                current={this.props.current}
            // style={{position:'relative'}}
            />
        )
    }
}
